package com.relife.sys.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.relife.common.model.AjaxJson;
import com.relife.common.model.Page;
import com.relife.common.utils.StringUtil;
import com.relife.core.easyui.Easyui;
import com.relife.core.entity.HomeSettingEntity;
import com.relife.core.qbc.QbcQuery;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;



@Controller
@RequestMapping("sys/homeSetting")
public class HomeSettingController extends BaseController {
	/**
	 * 页面
	 * 
	 * @author WU
	 * @date 2015-5-20 下午7:54:20
	 * @return
	 */
	@RequestMapping
	public String homeSettingList() {
		return "sys/homeSetting/homeSettingList";
	}

	/**
	 * 数据列表
	 * 
	 * @author WU
	 * @date 2015-5-20 下午7:54:08
	 * @param page
	 */
	@RequestMapping
	public void listData(HomeSettingEntity set, Page page, HttpServletResponse res) {
		QbcQuery qbc = new QbcQuery(set);
		service.getPage(qbc, page);
		Easyui.datagrid(page, res);
	}

	/**
	 * 
	 * @author WU
	 * @date 2016年5月25日 上午10:18:54
	 * @param req
	 * @return
	 */
	@RequestMapping
	public String homeSetting(HomeSettingEntity set, HttpServletRequest req) {
		if (StringUtil.isNotEmpty(set.getId())) {
			set = service.get(HomeSettingEntity.class, set.getId());
		}
		req.setAttribute("page", set);
		return "sys/homeSetting/homeSetting";
	}

	/**
	 * 
	 * @author WU
	 * @date 2017年3月6日 上午11:53:50
	 * @param set
	 * @return
	 */
	@ResponseBody
	@RequestMapping
	public AjaxJson save(HomeSettingEntity set) {
		AjaxJson j = new AjaxJson();
		try {
			service.saveOrUpdate(set);
		} catch (Exception e) {
			e.printStackTrace();
			j.setException(e);
		}
		return j;
	}

	/**
	 * 
	 * @author WU
	 * @date 2017年3月6日 上午11:54:17
	 * @param set
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/del")
	public AjaxJson del(HomeSettingEntity set) {
		AjaxJson j = new AjaxJson();
		try {
			service.delete(set);
		} catch (Exception e) {
			e.printStackTrace();
			j.setException(e);
		}
		return j;
	}

}
